<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <h1>黑马头条</h1>
      <div class="TopRight">
        <img
          v-if="userInfo.head_img"
          :src="$axios.defaults.baseURL + userInfo.head_img"
          alt=""
        />
        <img v-else src="@/assets/logo.png" alt class="headerAvatar" />
        <span class="TopName">{{ userInfo.nickname }}</span>
        <el-button type="info" @click="logout">退出</el-button>
      </div>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside>
        <el-menu>
          <el-menu-item index="2" @click="jumpPage('/newslist')">
            <i class="el-icon-menu"></i>
            <span slot="title">文章列表</span>
          </el-menu-item>
          <el-menu-item index="4" @click="jumpPage('/releasenews')">
            <i class="el-icon-setting"></i>
            <span slot="title">发布文章</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>用户管理</el-breadcrumb-item>
          <el-breadcrumb-item>用户列表</el-breadcrumb-item>
        </el-breadcrumb>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem('user')),
      menulist: []
    }
  },
  created() {
    this.getMenuList()
  },
  methods: {
    getMenuList() {
      this.$axios({
        url: '/post'
      }).then(res => {
        this.menulist = res.data.data

        console.log(this.menulist)
      })
    },
    jumpPage(path) {
      if (this.$route.path !== path) {
        this.$router.push(path)
      }
    },
    logout() {
      this.$message.success('退出成功')
      localStorage.clear()
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.home-container {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  align-items: center;
  h1 {
    flex: 1;
    font-size: 24px;
    padding-left: 30px;
    margin: 0 auto;
  }
  .TopRight {
    display: flex;
    align-items: center;
    img {
      border: 1px solid #888;
      width: 50px;
      height: 50px;
      border-radius: 25px;
      margin: 0 10px;
    }
    .TopName {
      color: #fff;
    }
    .el-button {
      margin: 0 20px 0 40px;
    }
  }
}

.el-aside {
  background-color: #333744;
  .el-menu {
    background-color: #333744;
    .el-menu-item {
      color: #888;
    }
  }
}

.el-main {
  background-color: #eaedf1;
}

.el-breadcrumb {
  margin-bottom: 20px;
}
</style>
